package com.lanou.order.controller;

import com.lanou.entity.entity.OrderEntity;
import com.lanou.entity.entity.OrderShippingEntity;
import com.lanou.entity.utils.AjaxResult;
import com.lanou.order.service.OrderService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    @RequestMapping("/query")
    public Map query(int page, String submitDate, String orderState, String keyWord){
        
        List<OrderEntity> list = this.orderService.query(page, submitDate, orderState, keyWord);

        return Collections.singletonMap("message", list);

    }

    @RequestMapping("/queryState")
    public Map queryState(){

        List<Integer> list = this.orderService.queryState();

        return Collections.singletonMap("message", list);

    }

    @RequestMapping("/queryAll")
    public Map queryAll(int page){

        List<OrderEntity> list = this.orderService.queryAll(page);
        return Collections.singletonMap("message", list);

    }


    @RequestMapping("/delete")
    public Map delete(int orderId){

        System.out.println(orderId);
        this.orderService.delete(orderId);

        return Collections.singletonMap("message","OK");
    }

    @RequestMapping("/insert")
    public Map insert(List itemIdList){
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setPayment("222.0");
        orderEntity.setPaymentType(1);
//        OrderItemEntity orderItemEntity = new OrderItemEntity();

        OrderShippingEntity orderShippingEntity = new OrderShippingEntity();
        orderShippingEntity.setReceiverName("张三");
        orderShippingEntity.setReceiverPhone("189855655");
        orderShippingEntity.setReceiverAddress("北京");
//        this.orderService.insert(orderEntity,orderShippingEntity,itemIdList);

        return Collections.singletonMap("message","OK");
    }

    @PostMapping("/info")
    public AjaxResult order(OrderShippingEntity orderShippingEntity,
                            String payType,
                            String userOrderCartId,
                            String total){

        return this.orderService.insert(orderShippingEntity,
                payType,
                userOrderCartId,
                total);


    }

    @RequestMapping("/queryCount")
    public Map queryCount(){
        int count = this.orderService.queryCount();

        return Collections.singletonMap("count",count);
    }

    @RequestMapping("/update")
    public Map update(String orderId, String status){

        this.orderService.update(orderId, status);
        return Collections.singletonMap("message","OK");
    }


}
